package algorithm.array;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

/**
 * 找到数组中消失的数字
 */
public class FindDisappearedNumber {


    public static void main(String[] args) {

        int [] arr = {4,3,2,7,8,2,3,1};
        System.out.println(findDisappearedNumbers(arr).toString());

    }

    public static List<Integer> findDisappearedNumbers(int[] nums) {
        HashSet hashSet = new HashSet<>();
        List<Integer> list = new ArrayList<>();

        for (int i = 0; i < nums.length; i++) {
            hashSet.add(nums[i]);
        }

        int size = nums.length;
        int start = 1;

        while (start <= size){
            if (!hashSet.contains(start)){
                list.add(start);
            }
            start ++;
        }

        return list;
    }
}
